<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="left">
				<u-form-item prop="nickName" label="提现通道" label-width="auto">
					<view slot="right">
						<u-radio-group v-model="payType">
							<u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.name">
								{{item.name}}
							</u-radio>
						</u-radio-group>
					</view>

				</u-form-item>
				<u-form-item prop="payName" label="真实姓名" label-width="auto">
					<u-input v-model="formData.payName" placeholder="请输入真实姓名" input-align="right" />
				</u-form-item>
				<u-form-item prop="payBankNumber" label="银行卡号" label-width="auto" v-if="payType=='银行卡'">
					<u-input v-model="formData.payBankNumber" placeholder="请输入银行卡号" type="number" input-align="right" />
				</u-form-item>
				<u-form-item prop="payAccount" label="支付宝账号" label-width="auto" v-else>
					<u-input v-model="formData.payAccount" placeholder="请输入支付宝账号" input-align="right" />
				</u-form-item>
				<u-form-item prop="payBankName" label="开户行" label-width="auto" v-if="payType=='银行卡'">
					<u-input v-model="formData.payBankName" placeholder="请输入开户行" input-align="right" />
				</u-form-item>

			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" :disabled="btnDisabled" shape="circle" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js';
	const apiKey = uni.getStorageSync('apiKey') || 'api';
	const baseUrlObj = config.Global.baseUrl;
	const baseUrl = config.Global.baseUrl[apiKey].apiUrl;
	export default {
		name: 'userInfo',
		data() {
			return {
				formData: {
					payType: 1,
					payName: null,
					payAccount: null,
					payBankName: null,
					payBankNumber: null
				},
				btnDisabled: false,
				list: [{
						name: '银行卡'
					},
					{
						name: '支付宝'
					}
				],
				payType: "银行卡"
			}
		},
		onLoad(options) {
			try {
				const userProvider = uni.getStorageSync(config.Global.cache + '_UserProvider');;

				if (userProvider) {
					this.$helper.ajax({
						url: "/api/Jiushi/Userextend/GetUserInfo",
						method: "GET",
						contentType: "application/json",
						success: res => {
							this.formData = res.data.data
							this.payType = (res.data.data.payType == null || res.data.data.payType == 1) ?
								'银行卡' : '支付宝'
						}
					});
				}
			} catch (e) {}

		},
		methods: {
			/* 表单提交 */
			onSubmit() {
				this.$helper.ajax({
					url: `/api/Jiushi/Userextend/${this.formData.id}`,
					method: "PUT",
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg('保存成功', 'success');
						uni.navigateBack();
					}
				});
			},
			radioChange(e) {
				this.payType = e
				this.formData.payType = e == '银行卡' ? 1 : 2
			}
		}
	}
</script>

<style scoped lang="scss">
	.page {
		height: 80vh;
	}
</style>